package com.guli.order.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.guli.common.utils.Query;

import com.guli.order.mapper.OrderItemMapper;
import com.guli.order.entity.OrderItemEntity;
import com.guli.order.service.OrderItemService;
import org.springframework.util.StringUtils;


@Service("orderItemService")
public class OrderItemServiceImpl extends ServiceImpl<OrderItemMapper, OrderItemEntity> implements OrderItemService {

    @Override
    public Page<OrderItemEntity> queryPage(Integer currentPage, Integer size, Map<String, Object> params) {

        Page<OrderItemEntity> page = new Page<>(currentPage, size);

        return this.page(page);
    }

    public List<OrderItemEntity> getItemsByOrderSn(String orderSn) {
        QueryWrapper<OrderItemEntity> wrapper = new QueryWrapper<>();

        wrapper.eq("order_sn",orderSn);

        return this.list(wrapper);
    }

    @Override
    public String getItemsNameByOrderSn(String orderSn) {

        List<String> collect = this.getItemsByOrderSn(orderSn).stream().map(item -> {
            return item.getSkuName();
        }).collect(Collectors.toList());


        return StringUtils.collectionToDelimitedString(collect,",");
    }

}